//
//  DYJQuestionTableViewCell.m
//  Piece
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "DYJQuestionTableViewCell.h"

@implementation DYJQuestionTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 5;
       
        //问题
        self.questionImageView = [[UIImageView alloc] init];
        self.questionImageView.image = [UIImage imageNamed:@"read_question"];
        [self.contentView addSubview:_questionImageView];
        
        self.questionTitleLabel = [[UILabel alloc] init];
        self.questionTitleLabel.numberOfLines = 0;
        self.questionTitleLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_questionTitleLabel];
        
        self.questionContentLabel = [[UILabel alloc] init];
        self.questionContentLabel.textColor = [UIColor colorWithRed:0.75 green:0.75 blue:0.75 alpha:1.00];
        self.questionContentLabel.font = [UIFont systemFontOfSize:14];
        self.questionContentLabel.numberOfLines = 0;
        [self.contentView addSubview:_questionContentLabel];
        
        self.questionLineView = [[UIView alloc] init];
        self.questionLineView.backgroundColor = [UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:1.00];
        [self.contentView addSubview:_questionLineView];

    }
    return self;
}
- (void)setQuestionModel:(DYJQuestionModel *)questionModel
{
    if (_questionModel != questionModel) {
        _questionModel = questionModel;
        self.questionTitleLabel.text = _questionModel.question_title;
        self.questionContentLabel.text = _questionModel.answer_title;
    }
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.questionImageView.frame = CGRectMake(10, 15, 48, 48);
    //规定字体的大小样式:
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName,nil];
    
    self.questionTitleLabel.frame =CGRectMake(60, 10, ScreenWidth - 90, 50);
    CGRect questionRect = [self.questionContentLabel.text boundingRectWithSize:CGSizeMake(self.questionTitleLabel.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.questionContentLabel.frame = CGRectMake(self.questionTitleLabel.frame.origin.x, self.questionTitleLabel.frame.origin.y + self.questionTitleLabel.frame.size.height - 3, questionRect.size.width, questionRect.size.height);
    
    self.questionLineView.frame = CGRectMake(self.questionContentLabel.frame.origin.x, self.questionContentLabel.frame.origin.y + self.questionContentLabel.frame.size.height + 10, ScreenWidth - 20 - self.questionContentLabel.frame.origin.x - 20, 1);

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
